
<%@ page import="auctionhaus.Listing;auctionhaus.Bid"%>

<g:set var="entityName"
	value="${message(code: 'listing.label', default: 'Listing')}" />



<div id="show-listing" class="content scaffold-show" role="main">
	<h1>
		<g:message code="default.detail.label" args="[listingInstance?.name]" />
	</h1>
	<g:if test="${flash.message}">
		<!-- UI-4: The action of placing a new bid will display a message to the user indicating that the bid was successful (Controller Unit Test) -->
		<div class="message" role="status">
			${flash.message}
		</div>
	</g:if>
	<%flash.message = null%>
	<ol class="property-list listing">

		<!-- L-1: The detail page for the listing shows the name of the listing -->
		<g:if test="${listingInstance?.name}">
			<li class="fieldcontain"><span id="name-label"
				class="property-label"><g:message code="listing.name.label"
						default="Name" /></span> <span class="property-value"
				aria-labelledby="name-label"><g:fieldValue
						bean="${listingInstance}" field="name" /></span></li>
		</g:if>

		<!-- L-2: The detail page for the listing shows the starting bid price of the listing -->
		<g:if test="${listingInstance?.startingPrice}">
			<li class="fieldcontain"><span id="startingPrice-label"
				class="property-label"><g:message
						code="listing.starting.price.label" default="Starting Price" /></span> <span
				class="property-value" aria-labelledby="startingPrice-label">
					${Bid.amountFormatter(listingInstance?.startingPrice)}
			</span></li>
		</g:if>




		<!--L-3: The detail page for the listing shows the most recent bid-->
		<g:if test="${listingInstance?.bids}">
			<li class="fieldcontain"><span id="bids-label"
				class="property-label"><g:message
						code="listing.recent.bids.label" default="Recent Bids" /></span> <%Bid b = listingInstance.bids.get(listingInstance.bids.size()-1 )%>

				<span class="property-value" aria-labelledby="bids-label"><g:remoteLink
						action="showRecentBids" controller="bid" update="returnedBids"
						params="[listingID: listingInstance?.id]">
						<g:message code="listing.show.recent.bids.label" default="Show" />
					</g:remoteLink>/<g:remoteLink action="hideRecentBids" controller="bid"
						update="returnedBids">
						<g:message code="listing.hide.recent.bids.label" default="Hide" />
					</g:remoteLink>
					<div id="returnedBids"></div> </span></li>



		</g:if>

		<li class="fieldcontain"><span id="bids-label"
			class="property-label"><g:message
					code="listing.numberOfBids.label" default="Number of Bids" /></span> <span
			class="property-value" aria-labelledby="bids-label"> ${listingInstance?.bids?.size()}</span>
		</li>

		<!--L-4: The detail page for the listing shows the end date/time of the listing-->
		<g:if test="${listingInstance?.endDateTime}">
			<li class="fieldcontain"><span id="endDateTime-label"
				class="property-label"><g:message
						code="listing.endDateTime.label" default="End Date Time" /></span> <span
				class="property-value" aria-labelledby="endDateTime-label"><g:formatDate
						date="${listingInstance?.endDateTime}" /></span></li>
		</g:if>

		<!-- L-5: The detail page for the listing optionally shows the description -->
		<g:if test="${listingInstance?.description}">
			<li class="fieldcontain"><span id="description-label"
				class="property-label"><g:message
						code="listing.description.label" default="Description" /></span> <span
				class="property-value" aria-labelledby="description-label"><g:fieldValue
						bean="${listingInstance}" field="description" /></span></li>
		</g:if>



		<!-- L-6: The detail page for the listing shows only the user portion of the email address of the user who created the listing (e.g. “mike” if the email address is “mike@piragua.com”) -->
		<g:if test="${listingInstance?.seller}">
			<li class="fieldcontain"><span id="seller-label"
				class="property-label"><g:message code="listing.seller.label"
						default="Seller" /></span> <span class="property-value"
				aria-labelledby="seller-label"><g:link controller="customer"
						action="show" id="${listingInstance?.seller?.id}">
						${listingInstance?.seller?.encodeAsHTML()}
					</g:link></span></li>
		</g:if>




		<g:if test="${listingInstance?.winner}">
			<li class="fieldcontain"><span id="winner-label"
				class="property-label"><g:message code="listing.winner.label"
						default="Winner" /></span> <span class="property-value"
				aria-labelledby="winner-label"><g:link controller="customer"
						action="show" id="${listingInstance?.winner?.id}">
						${listingInstance?.winner?.encodeAsHTML()}
					</g:link></span></li>
		</g:if>


		<!-- UI-3: The action of placing a new bid will update the new minimum bid price stored in the database and displayed to the user on the page -->
		<li class="fieldcontain"><span id="startingPrice-label"
			class="property-label"><g:message code="listing.min.bid.label"
					default="Minimum Bid" /></span> <span class="property-value"
			aria-labelledby="startingPrice-label">
				<div id="minBid">
					${Bid.amountFormatter(listingInstance?.currentMinimumBid)}
				</div>
		</span></li>


	</ol>

	<div id="placeBid">
		<g:form>
			<fieldset class="buttons">
				<sec:ifAnyGranted roles="ROLE_ADMIN">
					<g:hiddenField name="id" value="${listingInstance?.id}" />
					<g:link class="edit" action="edit" id="${listingInstance?.id}">
						<g:message code="default.button.edit.label" default="Edit" />
					</g:link>
					<g:actionSubmit class="delete" action="delete"
						value="${message(code: 'default.button.delete.label', default: 'Delete')}"
						onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
				</sec:ifAnyGranted>
				<sec:ifAnyGranted roles="ROLE_USER">
						<g:remoteLink class="create" controller="bid" action="createAjax"
							update="placeBid" params="['listing.id': listingInstance?.id]">
							${message(code: 'default.add.label', args: [message(code: 'bid.label', default: 'Bid')])}
						</g:remoteLink>
				</sec:ifAnyGranted>
			</fieldset>
		</g:form>
	</div>

</div>


